<?php 
include_once '../kelas/record.php';
include_once '../kelas/kategori.php';
include_once '../kelas/produk.php';
include_once '../kelas/fungsi.php';
include_once '../kelas/amankanParam.php';
include_once '../kelas/rekening.php';
$objParamAman = new amankanParam();
$dtGet = $objParamAman->getMethod();
$dtPost= $objParamAman->postMethod();
$dtPerPage = 3;
$dtRek = $objRekening->getData();
?>
<h3>Rekening</h3>
<form name="formRekening" method="POST" action="<?php echo BASEURL.'proses/rekening.php?on=simpan' ?>">
	<input name="id" type="hidden" /></input>
	<table class="form-produk">
		<tr>
			<td>Nama Bank</td> 
			<td><input type="text"class="text_box_3" required="required" name="bank" /></td>
		</tr>

		<tr>
			<td>Nomor Rekening</td>
			<td><input type="text" class="text_box_3"  required="required" name="norek" /></td>
		</tr>
		<tr>
			<td>Atas Nama</td>
			<td><input type="text" class="text_box_3"  required="required" name="atasnama" /></td>
		</tr>

		<tr>
			<td>Cabang</td>
			<td><input type="text" class="text_box_3"  required="required" name="cabang" /></td>
		</tr>

		<tr>
			<td>Aktif</td>
			<td><input type="checkbox" class="text_box_3" name="aktif" /></td>
		</tr>
		<tr>
			<td colspan="2">
				<input type="submit" value="Simpan">
				<input type="reset" value="Reset">
			</td>
		</tr>
	</table>
</form>
<div class="frame_table_order">
<table width="100%" cellpadding="5" cellspacing="0" border="1" style="border-collapse:collapse">

    <thead>
        <tr align="center" valign="middle" bgcolor="#CCCCCC">
		<th>No</th>
		<th>Bank</th>
		<th>Rekening</th>
		<th>Nama</th>
		<th>Cabang</th>
		<th>Aktif</th>
		<th colspan="2">Pilihan</th>
	</tr>
</thead>
<tbody>
<?php
$no = 1; 
if($dtRek['total']==0){
    ?>            <tr class="font_isi_judul" align="center" valign="middle">

        <td colspan="6">(tidak ada data)</td>
        
    </tr><?php
}
	else{
foreach($dtRek['result'] as $vRek){
?>
            <tr class="font_isi_judul" align="center" valign="middle">
	<td><?php echo $no++; ?></td>
	<td><?php echo $vRek['bank']; ?></td>
	<td><?php echo $vRek['norek']; ?></td>
	<td><?php echo $vRek['atasnama']; ?></td>
	<td><?php echo $vRek['cabang']; ?></td>
	<td><a href="#" class="<?php echo ($vRek['aktif'] == 1) ? "iconActive" : "iconNonaktif"; ?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a></td>
	<td>
		<a class="option aktifrek" href="#"
		data-id="<?php echo $vRek['id']; ?>" data-aktif="<?php echo (string)$vRek['aktif']; ?>"><?php echo $vRek['aktif']==1?"Nonaktifkan":"Aktifkan"; ?></a>
	</td>
	<td>
		<a class="option editrek" 
		data-id="<?php echo $vRek['id'] ?>" 
		data-bank="<?php echo $vRek['bank'] ?>" 
		data-norek="<?php echo $vRek['norek'] ?>"
		data-atasnama="<?php echo $vRek['atasnama'] ?>"
		data-cabang="<?php echo $vRek['cabang'] ?>"
		href="<?php echo $vRek['id']; ?>">Edit</a>
	</td>
	
</tr>
<?php
}
	}
 ?>
</tbody>
<tfoot></tfoot>
</table>
</div>
<script type="text/javascript">
	$(document).ready(function(){
		var frmRek = $(document).find('form[name="formRekening"]');
		frmRek.find('input[type="reset"]').click(function(e){
			frmRek.find('input[name="id"]').val('');
			frmRek.find('input[type="submit"]').val('Simpan');
		});
		frmRek.validate({
			rules:{
				bank:{
					minlength:3					
				},
				norek:{
					minlength:14,
					number:true
				},
				atasnama:{
					minlength:3
				},
				cabang:{
					minlength:5
				}
			}
		});
		$('.editrek').click(function(e){
			var dataSet = e.currentTarget.dataset;
			frmRek.find('input[name="id"]').val(dataSet.id);
			frmRek.find('input[name="bank"]').val(dataSet.bank);
			frmRek.find('input[name="norek"]').val(dataSet.norek);
			frmRek.find('input[name="atasnama"]').val(dataSet.atasnama);
			frmRek.find('input[name="cabang"]').val(dataSet.cabang);
			frmRek.find('input[type="submit"]').val("Update");
e.preventDefault();
		});
		$('.aktifrek').click(function(e){
			var dataSet=e.currentTarget.dataset;
			$.ajax({
				url:baseUrl+'proses/rekening.php?on=aktifasi',
				dataType:'JSON',
				type:"POST",
				data:{
					id:dataSet.id,
					aktif:dataSet.aktif==1?0:1
				},
				success:function(resp){
					if(resp.success==true){
					document.location=document.URL;			
					}
					else{
						alert(resp.error_msg);
					}
				}

			});
			
			e.preventDefault();
		});
	});
</script>